package BOH.GUI;
import BOH.data.TableConnection;
import java.awt.event.*;
import javax.swing.*;

/**
 * The Back of House System for a
 * small restaurant.
 * 
 * Maeghan Colvin & Jennifer Haveman
 * CSC 289 0B01
 * February 13, 2014
 */

public class MainFrame extends JFrame
{
    // The following reference menu components
    private JMenuBar menuBar;           // Displays the menu bar
    private JMenu fileMenu;             // Displays the file menu
    private JMenu employeeMenu;         // Displays the employee menu
    private JMenu inventoryMenu;        // Displays the stores inventory information
    private JMenu salesMenu;            // Displays the sales information
    private JMenuItem addEmployeeItem;  // Used to add new employees
    private JMenuItem viewEmployeesItem;// Used to view all employee information
    private JMenuItem viewPayrollItem;  // Used to view payroll for all employees
    private JMenuItem editPayrollItem;  // Used to stop sound
    private JMenuItem insertPayrollItem;// Used to get employee payroll forms
    private JMenuItem viewInventoryItem;// Used to view inventory information
    private JMenuItem countInventoryItem;// Used to count inventory
    private JMenuItem viewSalesItem;    // Used to view sales information
    private JMenuItem viewTotalSalesItem;// Used to view total sales
    private JMenuItem viewTillCountItem; // Used to find till information
    private JMenuItem exitItem;         // Used to exit program
    
    
    /**
     * Constructor
     */
    public MainFrame() 
    {
        try 
        {
            UIManager.setLookAndFeel(
                UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException e) { }
 
        // Set title
        this.setTitle("I Don't Know Eatery");

        // Exit on close
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Add menu bar
        buildMenuBar();
        
        // Set resizeable
        this.setResizable(false);

        // Set size and view screen
        this.setSize(1200, 700);
        this.setVisible(true);
    }
    
    private void buildMenuBar()
    {
        // Create the menu bar
        menuBar = new JMenuBar();
        
        // Create the file menu
        buildFileMenu();
        buildEmployeeMenu();
        buildInventoryMenu();
        buildSalesMenu();
        
        // Add the file menu to the menu bar
        menuBar.add(fileMenu);
        menuBar.add(employeeMenu);
        menuBar.add(inventoryMenu);
        menuBar.add(salesMenu);
        
        // Set menu bar
        setJMenuBar(menuBar);
    }
    
    /**
     * The buildFileMenu method builds the file menu
     * and returns a reference to its menu object
     */
    
    private void buildFileMenu()
    {
        // Create an exit button menu item
        exitItem = new JMenuItem("Exit");
        exitItem.setMnemonic(KeyEvent.VK_X);
        exitItem.addActionListener(new ExitActionListener());
        
        // Create a JMenu object for the File menu
        fileMenu = new JMenu("File");
        fileMenu.setMnemonic(KeyEvent.VK_F);
        
        // Add file items
        fileMenu.add(exitItem);
    }
    
    /**
     * The buildEmployeeMenu method builds the employee menu
     * and returns a reference to its menu object
     */
    
    private void buildEmployeeMenu()
    {
        // Create a JMenu object for the employee menu
        employeeMenu = new JMenu("Employees");
        employeeMenu.setMnemonic(KeyEvent.VK_E);
        
        // Create the view employee button menu item
        viewEmployeesItem = new JMenuItem("View Employees");
        viewEmployeesItem.setMnemonic(KeyEvent.VK_E);
        viewEmployeesItem.addActionListener(new ViewEmployeeActionListener());
        
        // Create the add employee button menu item
        addEmployeeItem = new JMenuItem("Add/Edit/Remove");
        addEmployeeItem.setMnemonic(KeyEvent.VK_A);
        addEmployeeItem.addActionListener(new AddEditEmployeeActionListener());
        
        // Create the view payroll button menu item
        viewPayrollItem = new JMenuItem("View Payroll Information");
        viewPayrollItem.setMnemonic(KeyEvent.VK_V);
        viewPayrollItem.addActionListener(new ViewPayrollActionListener());
        
        // Create the insert payroll button menu item
        insertPayrollItem = new JMenuItem("Insert Payroll Information");
        insertPayrollItem.setMnemonic(KeyEvent.VK_I);
        insertPayrollItem.addActionListener(new InsertPayrollActionListener());
        
        // Create the edit payroll button menu item
        editPayrollItem = new JMenuItem("Edit Clock In/out Time");
        editPayrollItem.setMnemonic(KeyEvent.VK_E);
        editPayrollItem.addActionListener(new EditPayrollActionListener());
        
        // Add employee items
        employeeMenu.add(viewEmployeesItem);
        employeeMenu.add(addEmployeeItem);
        employeeMenu.addSeparator();        // Add separator
        employeeMenu.add(viewPayrollItem);
        employeeMenu.add(editPayrollItem);
        employeeMenu.add(insertPayrollItem);
    }
    
    /**
     * The buildInventoryMenu method builds the inventory menu
     * and returns a reference to its menu object
     */
    
    private void buildInventoryMenu()
    {
        // Create a JMenu object for the Inventory menu
        inventoryMenu = new JMenu("Inventory");
        inventoryMenu.setMnemonic(KeyEvent.VK_I);
        
        // Create a view inventory button menu item
        viewInventoryItem = new JMenuItem("View Inventory");
        viewInventoryItem.setMnemonic(KeyEvent.VK_V);
        viewInventoryItem.addActionListener(new ViewInventoryActionListener());
        
        // Create a view inventory button menu item
        countInventoryItem = new JMenuItem("Count Inventory");
        countInventoryItem.setMnemonic(KeyEvent.VK_C);
        countInventoryItem.addActionListener(new CountInventoryActionListener());
        
        // Add inventory items
        inventoryMenu.add(viewInventoryItem);
        inventoryMenu.add(countInventoryItem);
    }
    
    /**
     * The buildSalesMenu method builds the sales menu
     * and returns a reference to its menu object
     */
    
    private void buildSalesMenu()
    {
        // Create a JMenu object for the Sales menu
        salesMenu = new JMenu("Sales");
        salesMenu.setMnemonic(KeyEvent.VK_S);
        
        // Create a view sales button menu item
        viewSalesItem = new JMenuItem("View All Sales");
        viewSalesItem.setMnemonic(KeyEvent.VK_A);
        viewSalesItem.addActionListener(new ViewSalesActionListener());
        
        // Create a view total sales button menu item
        viewTotalSalesItem = new JMenuItem("View Total Sales");
        viewTotalSalesItem.setMnemonic(KeyEvent.VK_T);
        viewTotalSalesItem.addActionListener(new ViewTotalSalesActionListener());
        
        // Create a view till information button menu item
        viewTillCountItem = new JMenuItem("View Till Information");
        viewTillCountItem.setMnemonic(KeyEvent.VK_V);
        viewTillCountItem.addActionListener(new ViewTillCountActionListener());
        
        // Add sales items
        salesMenu.add(viewSalesItem);
        salesMenu.add(viewTotalSalesItem);
        salesMenu.addSeparator();
        salesMenu.add(viewTillCountItem);
    }
    
    /**
     * The ViewEmployeeActionListener view
     * all of the employee information.
     */
    
    private class ViewEmployeeActionListener implements ActionListener 
    {
        @Override
        public void actionPerformed(ActionEvent e) 
        {
            // View employee information
            String sqlStatement = "SELECT * " +
                           "FROM Employee";
            TableConnection dbQuery = new TableConnection(sqlStatement);
            String[] columnNames = dbQuery.getColumnNames();
            String[][] tableData = dbQuery.getTableData();
            GetTableResults table = new GetTableResults(tableData, columnNames);
        }
    }
    
    /**
     * The AddEditEmployeeActionListener opens the 
     * add/edit employee screen.
     */
    
    private class AddEditEmployeeActionListener implements ActionListener 
    {
        @Override
        public void actionPerformed(ActionEvent e) 
        {
            // Open the add/edit employee screen
            SearchEmployeePanel addEditEmployeeMenu = new SearchEmployeePanel();
        }
    }
    
    /**
     * The ViewPayrollActionListener gets proper
     * information to view payroll information.
     */
    
    private class ViewPayrollActionListener implements ActionListener 
    {
        @Override
        public void actionPerformed(ActionEvent e) 
        {
            // View Payroll
            String sqlStatement = "SELECT * " +
                           "FROM Payroll";
            TableConnection dbQuery = new TableConnection(sqlStatement);
            String[] columnNames = dbQuery.getColumnNames();
            String[][] tableData = dbQuery.getTableData();
            GetTableResults table = new GetTableResults(tableData, columnNames);
        }
    }
    
    /**
     * The EditPayrollActionListener gets proper
     * information to view payroll information.
     */
    
    private class EditPayrollActionListener implements ActionListener 
    {
        @Override
        public void actionPerformed(ActionEvent e) 
        {
            // View edit clock in/out screen
            EditClockInOutPanel editClockIn = new EditClockInOutPanel();
        }
    }
    
    /**
     * The InsertPayrollActionListener gets proper
     * information to insert payroll information.
     */
    
    private class InsertPayrollActionListener implements ActionListener 
    {
        @Override
        public void actionPerformed(ActionEvent e) 
        {
            // Open the insert payroll screen
            InsertPayrollPanel insertPayroll = new InsertPayrollPanel();
        }
    }
    
    /**
     * The ViewInventoryActionListener gets proper
     * information to insert payroll information.
     */
    
    private class ViewInventoryActionListener implements ActionListener 
    {
        @Override
        public void actionPerformed(ActionEvent e) 
        {
            // View inventory
            String sqlStatement3 = "SELECT * " +
                           "FROM Inventory";
            TableConnection dbQuery = new TableConnection(sqlStatement3);
            String[] columnNames = dbQuery.getColumnNames();
            String[][] tableData = dbQuery.getTableData();
            GetTableResults table = new GetTableResults(tableData, columnNames);
        }
    }
    
    /**
     * The CountInventoryActionListener view
     * opens the inventory count sheet.
     */
    
    private class CountInventoryActionListener implements ActionListener 
    {
        @Override
        public void actionPerformed(ActionEvent e) 
        {
            // View inventory count sheet
            InventoryUpdatePanel countSheet = new InventoryUpdatePanel();
        }
    }
    
    /**
     * The ViewSalesActionListener view
     * all of the sales information.
     */
    
    private class ViewSalesActionListener implements ActionListener 
    {
        @Override
        public void actionPerformed(ActionEvent e) 
        {
            // View sales
            String sqlStatement1 = "SELECT * " +
                           "FROM Sales";
            TableConnection dbQuery = new TableConnection(sqlStatement1);
            String[] columnNames = dbQuery.getColumnNames();
            String[][] tableData = dbQuery.getTableData();
            GetTableResults table = new GetTableResults(tableData, columnNames);
        }
    }
    
    /**
     * The ViewTotalSalesActionListener view
     * the total sales information for a select date.
     */
    
    private class ViewTotalSalesActionListener implements ActionListener 
    {
        @Override
        public void actionPerformed(ActionEvent e) 
        {
            // View total sales
            ViewTotalSalesPanel totalSales = new ViewTotalSalesPanel();
        }
    }
    
    /**
     * The ViewTillCountActionListener views
     * the till information for the day.
     */
    
    private class ViewTillCountActionListener implements ActionListener 
    {
        @Override
        public void actionPerformed(ActionEvent e) 
        {
            // View total sales
            TillCountPanel tillCount = new TillCountPanel();
        }
    }
    
    /**
     * The ExitActionListener exits the program
     */
    
    private class ExitActionListener implements ActionListener 
    {
        @Override
        public void actionPerformed(ActionEvent e) 
        {
            // Exit programViewTillCountActionListener()
            System.exit(0);
        }
    }
}
